﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using AjaxControlToolkit;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_HWP : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnOK.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并提交么？" + "')== false) return false;");
    }
    public void ddlKu_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlKu.SelectedIndex != 0)
        {
            string cday = DateTime.Now.ToShortDateString().ToString();
            switch (ddlKu.SelectedValue.ToString())
            {
                case "嘉东库":
                    {
                        ddlPinzhong.Visible = true;
                        Label8.Visible = true;
                        Label9.Visible = false;
                        txtKC.Visible = false;
                        Label6.Visible = true;
                        txtPZKC.Visible = true;

                    }; break;
                case "板材库":
                    {
                        txtKC.Text = BLLFactory.CreateZkcdtBLL().KuKC(cday);
                        txtKC.Attributes["contentEditable"] = "false";

                    }; break;
                case "不锈钢热轧库":
                    {
                        txtKC.Text = BLLFactory.CreateRkcdtBLL().KuKC(cday, "不锈钢热轧库");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "不锈钢冷轧库":
                    {
                        txtKC.Text = BLLFactory.CreateLkcdtBLL().KuKC(cday, "不锈钢冷轧库");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "碳钢热轧库":
                    {
                        txtKC.Text = BLLFactory.CreateRkcdtBLL().KuKC(cday, "碳钢热轧库");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "碳钢冷轧库":
                    {
                        txtKC.Text = BLLFactory.CreateRkcdtBLL().KuKC(cday, "碳钢冷轧库");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "一高线":
                    {
                        string xc = BLLFactory.CreateXkcdtBLL().KuKC(cday, "一高线");
                        decimal xckc = 0;
                        if (xc != "")
                            xckc = Convert.ToDecimal(xc);
                        string bc = BLLFactory.CreateBkcdtBLL().KuKC(cday, "一高线");
                        decimal bckc = 0;
                        if (bc != "")
                            bckc = Convert.ToDecimal(bc);
                        txtKC.Text = (xckc + bckc).ToString("f2");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "二高线":
                    {
                        string xc = BLLFactory.CreateXkcdtBLL().KuKC(cday, "二高线");
                        decimal xckc = 0;
                        if (xc != "")
                            xckc = Convert.ToDecimal(xc);
                        string bc = BLLFactory.CreateBkcdtBLL().KuKC(cday, "二高线");
                        decimal bckc = 0;
                        if (bc != "")
                            bckc = Convert.ToDecimal(bc);
                        txtKC.Text = (xckc + bckc).ToString("f2");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "大棒线":
                    {
                        string xc = BLLFactory.CreateXkcdtBLL().KuKC(cday, "大棒线");
                        decimal xckc = 0;
                        if (xc != "")
                            xckc = Convert.ToDecimal(xc);
                        string bc = BLLFactory.CreateBkcdtBLL().KuKC(cday, "大棒线");
                        decimal bckc = 0;
                        if (bc != "")
                            bckc = Convert.ToDecimal(bc);
                        txtKC.Text = (xckc + bckc).ToString("f2");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "四轧库":
                    {
                        string xc = BLLFactory.CreateXkcdtBLL().KuKC(cday, "四轧库");
                        decimal xckc = 0;
                        if (xc != "")
                            xckc = Convert.ToDecimal(xc);
                        string bc = BLLFactory.CreateBkcdtBLL().KuKC(cday, "四轧库");
                        decimal bckc = 0;
                        if (bc != "")
                            bckc = Convert.ToDecimal(bc);
                        txtKC.Text = (xckc + bckc).ToString("f2");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "酸洗库":
                    {
                        txtKC.Text = BLLFactory.CreateRkcdtBLL().KuKC(cday, "酸洗库");
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
                default:
                    {
                        txtKC.Text = "";
                        txtKC.Attributes["contentEditable"] = "false";
                    }; break;
            }
        }
        
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        int checkValue = 0;
        HweekplanInfo hwp = new HweekplanInfo();
        if (ddlKu.SelectedValue.ToString() == "嘉东库" && ddlPinzhong.SelectedIndex != 0)
        {
            switch (ddlPinzhong.SelectedValue.ToString())
            {
                case "线材":
                    hwp.Ku = "嘉东线材"; break;
                case "螺纹":
                    hwp.Ku = "嘉东螺纹"; break;
                case "卷板":
                    hwp.Ku = "嘉东卷板"; break;
                case "板材":
                    hwp.Ku = "嘉东板材"; break;
                default:
                    break;


            }
        }
        else if (ddlKu.SelectedValue.ToString() != "嘉东库")
            hwp.Ku = ddlKu.SelectedValue.ToString();
        
        hwp.Sday = Convert.ToDateTime(txtSday.Text.ToString()).ToShortDateString().ToString();
        hwp.Eday = Convert.ToDateTime(txtEday.Text.ToString()).ToShortDateString().ToString();
        hwp.Wcl = Convert.ToDecimal(txtWcl.Text.ToString());
        hwp.Xday = DateTime.Now.ToShortDateString().ToString();
        hwp.Num = BLLFactory.CreateHweekplanBLL().AUTOID();
        checkValue = BLLFactory.CreateHweekplanBLL().AddHweekplan(hwp);
        if (checkValue >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 提交成功！ ');</script> ");
        }
        if (txtJk.Text.ToString() != "")
            BLLFactory.CreateHweekplanBLL().UpdateHweekplanJK(hwp.Num, Convert.ToDecimal(txtJk.Text.ToString()));
        Response.Redirect("HWPJL.aspx");
    }
    protected void btnRepeat_Click(object sender, EventArgs e)
    {
        ddlKu.SelectedIndex = 0;
        txtSday.Text = "";
        txtEday.Text = "";
        txtWcl.Text = "";
        txtJk.Text = "";
    }

    public void ddlPinzhong_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPinzhong.SelectedIndex != 0)
        {
            string cday = DateTime.Now.ToShortDateString().ToString();
            switch (ddlPinzhong.SelectedValue.ToString())
            {
                case "线材":
                    {
                        txtPZKC.Text = BLLFactory.CreateXkcdtBLL().JDXC(cday);
                        txtPZKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "螺纹":
                    {
                        txtPZKC.Text = BLLFactory.CreateBkcdtBLL().JDBC(cday);
                        txtPZKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "卷板":
                    {
                        txtPZKC.Text = BLLFactory.CreateRkcdtBLL().JDJB(cday);
                        txtPZKC.Attributes["contentEditable"] = "false";
                    }; break;
                case "板材":
                    {
                        txtPZKC.Text = BLLFactory.CreateZkcdtBLL().JDZB(cday);
                        txtPZKC.Attributes["contentEditable"] = "false";
                    }; break;
                default:
                    break;

            }
        }
    }
}
